<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | 王勇程 <laughskydragon@qq.com>                         |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\admin\controller;

/**
 * 用户管理控制器
 */
class User extends AdminBase
{

    /**
     * 用户列表
     */
    public function userList()
    {
        $where = $this->logicUser->getWhere($this->param);
        
        $this->assign('list', $this->logicUser->getUserList($where));
        
        return $this->fetch('user_list');
    }
    
    /**
     * 用户详情
     */
    public function detail()
    {
        $info = $this->logicUser->getUserInfo(['id' => $this->param['id']]);
        
        $this->assign('info', $info);
        
        return $this->fetch('user_detail');
    }
    

    
    /**
     * 用户添加
     */
    public function add()
    {
        IS_POST && $this->jump($this->logicUser->userAdd($this->param));
        
        // 为添加操作设置空的info数组，确保模板中的默认值正确显示
        $this->assign('info', []);
        
        return $this->fetch('user_edit');
    }
    
    /**
     * 用户编辑
     */
    public function edit()
    {
        IS_POST && $this->jump($this->logicUser->userEdit($this->param));
        
        $info = $this->logicUser->getUserInfo(['id' => $this->param['id']]);
        
        $this->assign('info', $info);
        
        return $this->fetch('user_edit');
    }
    
    /**
     * 用户删除
     */
    public function delete()
    {
        $this->jump($this->logicUser->userDel($this->param));
    }
    
    /**
     * 用户状态切换
     */
    public function status()
    {
        $this->jump($this->logicUser->userStatus($this->param));
    }
    
    /**
     * 用户导出
     */
    public function export()
    {
        $where = $this->logicUser->getWhere($this->param);
        
        $this->logicUser->exportUserList($where);
    }
    
    /**
     * 用户VIP管理
     */
    public function vip()
    {
        IS_POST && $this->jump($this->logicUser->userVipManage($this->param));
        
        $info = $this->logicUser->getUserInfo(['id' => $this->param['id']]);
        
        $this->assign('info', $info);
        
        return $this->fetch('user_vip');
    }
    
    /**
     * 用户积分管理
     */
    public function points()
    {
        IS_POST && $this->jump($this->logicUser->userPointsManage($this->param));
        
        $info = $this->logicUser->getUserInfo(['id' => $this->param['id']]);
        
        $this->assign('info', $info);
        
        return $this->fetch('user_points');
    }
    
    /**
     * 用户余额流水（隐藏菜单）
     */
    public function balanceList()
    {
        $userId = intval($this->param['id'] ?? 0);
        $type = $this->param['type'] ?? '';
        $data = ['user_id' => $userId];
        if ($type !== '') { $data['type'] = $type; }
        $list = $this->logicInvite->getUserBalanceList($data);
        $this->assign('list', $list);
        return $this->fetch('user_balance_list');
    }
    
    /**
     * 用户佣金来源（隐藏菜单）
     */
    public function commissionList()
    {
        $userId = intval($this->param['id'] ?? 0);
        $list = $this->logicInvite->getUserCommissionSourceList(['user_id' => $userId]);
        $this->assign('list', $list);
        return $this->fetch('user_commission_list');
    }
    
    /**
     * 生成邀请码
     */
    public function generateInviteCode()
    {
        $this->jump($this->logicUser->generateInviteCode($this->param));
    }

}
